<?php
date_default_timezone_set("Asia/Shanghai");
$conn_args = array(
    'host' => 'localhost',
    'port' => 5672,
    'login' => 'admin',
    'password' => 'admin2021',
    'vhost' => 'why'
);
$ex_name = 'test_exchange';
$route = 'why.one';
$conn = new AMQPConnection($conn_args);
if(!$conn->connect())
{
    die("connect error");
}
$channel = new AMQPChannel($conn);
$exchange = new AMQPExchange($channel);
$exchange->setName($ex_name);
$exchange->setType('topic');
$exchange->declareExchange();
$message = 'test success';

//echo date('Y-m-d H:i:s', time()) .':' . $exchange->publish($message, $route) . "\n";


for ($i = 0; $i < 100; $i++) { 
    $arr = [
        'id' => 'message_' . $i,
        'order_id' => str_replace('.', '' , microtime(true)) . mt_rand(10, 99) . $i,
        'content' => 'helloweba-' . time()
    ];
    $data = json_encode($arr);
    $exchange->publish($data, $route);
    echo 'Send message: ' . $data . "\n";
}


$conn->disconnect();